import 'package:get/get.dart';
import 'package:mtf/app/data/UsdRecordEntity.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../utils/cache/AppCahche.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class transaction_recordController extends GetxController{

  var page =1;
  RefreshController refreshController = RefreshController(initialRefresh: true);
  RxList<ListUSDElement> usdList=<ListUSDElement>[].obs;
  void refreshData(){
    page=1;
    reqListData();
  }

  void loadData(){
    page+=1;
    reqListData();
  }
  void reqListData() async{
    if(AppCache.getUserInfo()!=null&&AppCache.getUserInfo().mt5Login!=null){
      var resp=await HttpManager.reqUsdRecord(page);
      if(resp.isSuccessData()){
        if(page==1){
          usdList.assignAll(resp.data!.list);
          refreshController.refreshCompleted();
        }else{
          usdList.addAll(resp.data!.list);
          if(resp.data!.list.isEmpty){
            refreshController.loadNoData();
          }else{
            refreshController.loadComplete();
          }
        }
      }
    }else{
      refreshController.loadNoData();
      refreshController.loadComplete();
    }

  }
}
